/**************************************************************************
*   Copyleft 2009 by        											  *
*	Iwanicki Krzysztof													  *
*   <www.gamma.mini.pw.edu.pl/~iwanickik>		                          *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
***************************************************************************/
#include "./vCamera.h"
#include "../Scene/vSceneManager.h"
#include "../vEngine3D.h"

namespace Vendetta {
	vVoid vCamera::Use() {
		updateProjection();
		vEngine3D::InstancePtr()->ViewPtr()->LoadIdentity();
		vEngine3D::InstancePtr()->ViewPtr()->LookAt(
				mPosition, mTarget, mUpDir
			);
	}

	vCamera::vCamera(const vString& name) {
		mName = name;
		mPosition = vVector3D::UnitZ * 200;
		mSpeed = vVector3D::Zero;
		mTarget = vVector3D(0, 1, 0.5);
		mUpDir = vVector3D(0, 0, 1);
		mFov = 45;
		mFarPlane = 5000;
		mNearPlane = 0.5;
		mRightDir = CrossProduct(mTarget - mPosition, mUpDir);
		mRightDir.Normalize();
	}

	vCamera::~vCamera() {
	
	}

	vVoid vCamera::updateProjection() const {
		vMainWindow* pWindow = vEngine3D::InstancePtr()->MainWindowPtr();
		vEngine3D::InstancePtr()->ViewPtr()->SetPerspective(
			mFov,											// Viewing angle
			pWindow->Width() / (vReal) pWindow->Height(),	// Aspect ratio
			mNearPlane,										// Near plane
			mFarPlane);										// Far plane
	}

	/************************************************************************/
	/* Disabled                                                             */
	/************************************************************************/
	vCamera::vCamera() {
		V_CHECK_MSG(0, "Some tries to call vCamera defauly ctor.") ;
	}

	vCamera::vCamera(const vCamera& camera) { 
		V_CHECK_MSG(0, "Some tries to call vCamera copy ctor.") ;
	}

	vCamera& vCamera::operator=(const vCamera& camera) { 
		V_CHECK_MSG(0, "Some tries to call vCamera operator=."); 
		return * this; 
	}
	/************************************************************************/
}